﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class DeleteAccount : System.Web.UI.Page
{
    public string messagetype = "";
    public string message = "";
    public ProxyWrapper.UserProxy.UserDetails UserObject { get; set; }
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {

            if (Session["userObject"] == null)
            {
                Response.Redirect("Default.aspx", false);
            }
            else
            {
                UserObject = ((ProxyWrapper.UserProxy.UserDetails)Session["UserObject"]);
                if (Request.QueryString["mode"] != null && Request.QueryString["mode"].ToString().Equals("deleteaccount"))
                {
                    ProxyWrapper.UserServiceWrapper _wrap = new ProxyWrapper.UserServiceWrapper();
                    string msg = _wrap.DeleteUserAccount(UserObject.UserName, UserObject.Password, UserObject.UserId, UserObject.HashCode);
                    if (!msg.Equals("failed"))
                    {
                        Session["UserObject"] = null;
                        Session.Clear();
                        Session.Abandon();
                        Response.Redirect("Default.aspx", false);
                    }
                    else
                    {
                        messagetype = "E";
                        message = "Unable to delete user. Please contact system Administrator";
                    }
                }
            }
        }
        catch (Exception ex)
        { }
    }
    public string GetMessage()
    {
        string warning = "<div class='warning'><p></p><li>{0}</li><p></p></div>";
        string result = "<div class='success'><p></p><li>{0}</li><p></p></div>";
        if (messagetype == "E")
            return string.Format(warning, message);
        else if (messagetype == "S")
            return string.Format(result, message);
        else
            return "";

    }
}